<template>
  <div id="pieEcharts"></div>
</template>
<script>
import * as echarts from "echarts";
export default {
  props: {
    pieData: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {};
  },
  methods: {
    drawChart() {
      let myChart = this.$echarts.init(document.getElementById("pieEcharts"));
      var option;
      option = {
        title: {
          text: "会员分布",
          subtext: "",
          left: "center",
        },
        tooltip: {
          trigger: "item",
        },
        legend: {
          orient: "vertical",
          left: "left",
        },
        series: [
          {
            name: "会员分布",
            type: "pie",
            radius: "50%",
            data: this.pieData,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };
      option && myChart.setOption(option);
      window.addEventListener("resize",function(){
		    myChart.resize();
		});
    },
  },
  //声明周期 - 创建完成（可以访问当前this实例）
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    setTimeout(() => {
      this.pieData = this.$props.pieData;
      this.drawChart();
    }, 500);
  },
};
</script>

<style lang="less" scoped>
#pieEcharts {
  width: 80%;
  height: 50vh;
  margin-top: 50px;
}
</style>
